import { isBoolean, isString } from '../utils/TypeUtils';
import { IDefault } from './IDefault';

export class BooleanDefault implements IDefault<boolean> {
  private TRUE = "true"
  private FALSE = "false"
  private mJsonValue: ESObject

  constructor(jsonValue: ESObject) {
    this.mJsonValue = jsonValue
  }

  asTargetType(): boolean {
    if (isBoolean(this.mJsonValue)) {
      return this.mJsonValue
    } else if (isString(this.mJsonValue)) {
      if (this.mJsonValue == this.TRUE) {
        return true
      } else if (this.mJsonValue == this.FALSE) {
        return false
      } else {
        return this.defaultValue()
      }
    }
    return this.defaultValue()
  }

  defaultValue(): boolean {
    return false
  }
}